var e = require("../../@babel/runtime/helpers/interopRequireDefault");

require("../../@babel/runtime/helpers/Objectvalues");

var t = e(require("../../@babel/runtime/regenerator")), r = require("../../@babel/runtime/helpers/createForOfIteratorHelper"), a = require("../../@babel/runtime/helpers/asyncToGenerator"), o = e(require("../../http/offlineShop")), n = e(require("../../http/robot")), u = require("../../utils/tool"), i = e(require("../../behavior/orderBehavior")), s = (new o.default(), 
new n.default());

Page({
    behaviors: [ i.default ],
    data: {
        orderNo: "",
        details: {},
        status: [ "未付款", "已关闭", "待出货", "已完成", "已退款", "退款中" ]
    },
    onLoad: function(e) {
        this.setData({
            orderNo: e.orderNo
        }), this.getDetail();
    },
    toGoodsDetails: function(e) {
        var t = e.currentTarget.dataset.productid;
        0 == e.currentTarget.dataset.producttype ? wx.navigateTo({
            url: "/pages/direct-buy-details/direct-buy-details?productId=".concat(t)
        }) : wx.navigateTo({
            url: "/pages/series/series?productId=".concat(t)
        });
    },
    getDetail: function() {
        var e = this;
        return a(t.default.mark(function a() {
            var o, n, i, d, c, l, p, f, b, h;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, wx.showLoading({
                        title: "加载中",
                        mask: !0
                    }), t.next = 4, s.robotOrderDetails(e.data.orderNo);

                  case 4:
                    (o = t.sent).data.totalPrice = o.data.totalAmount, o.data.activityAmount = o.data.robotActivityAmount, 
                    o.data.couponAmount = o.data.couponAmount, n = {}, i = r(o.data.orderItemList);
                    try {
                        for (i.s(); !(d = i.n()).done; ) c = d.value, l = "".concat(c.productId, "|").concat(c.productType), 
                        (p = n[l]) ? (p.quantity += c.quantity, p.refundCount += 1 == c.refundStatus ? c.quantity : 0) : (c.sort = Object.keys(n).length, 
                        c.refundCount = 1 == c.refundStatus ? c.quantity : 0, n[l] = c);
                    } catch (e) {
                        i.e(e);
                    } finally {
                        i.f();
                    }
                    (n = Object.values(n)).sort(function(e, t) {
                        return e.sort - t.sort;
                    }), f = !1, b = r(n), t.prev = 15, b.s();

                  case 17:
                    if ((h = b.n()).done) {
                        t.next = 24;
                        break;
                    }
                    if (!(h.value.refundCount > 0)) {
                        t.next = 22;
                        break;
                    }
                    return f = !0, t.abrupt("break", 24);

                  case 22:
                    t.next = 17;
                    break;

                  case 24:
                    t.next = 29;
                    break;

                  case 26:
                    t.prev = 26, t.t0 = t.catch(15), b.e(t.t0);

                  case 29:
                    return t.prev = 29, b.f(), t.finish(29);

                  case 32:
                    e.setData({
                        title: e.getRobotOrderStatusTitle(o.data.orderStatus),
                        productList: n,
                        hasRefund: f,
                        details: o.data
                    }), t.next = 39;
                    break;

                  case 35:
                    t.prev = 35, t.t1 = t.catch(0), console.log(t.t1), (0, u.toastToPage)(t.t1.msg);

                  case 39:
                    return t.prev = 39, wx.hideLoading(), t.finish(39);

                  case 42:
                  case "end":
                    return t.stop();
                }
            }, a, null, [ [ 0, 35, 39, 42 ], [ 15, 26, 29, 32 ] ]);
        }))();
    }
});